const { default: Toast } = require("../../../../component/vant/toast/toast.js");
// pages/couponlist/couponlist.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"),
common_Js = require("../../../../component/common.js")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    current: 0,
    state:0,
    pageSize:10,
    pageIndex:1,
    recordList:[],
    hasData:false,
    tabIndex:0,
    netWork:false,
    isLoading:true,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.id){
      this.data.store_id = options.id
    }
    this.onHttpInit();
  },
  /**
     * 获取页面数据的 http请求
     */
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost('/bingge/store/record/list', {
      store_id: that.data.store_id,
      pageSize: that.data.pageSize,
      pageIndex: that.data.pageIndex
    }, function (res) {
      console.log("销售记录列表数据", res)
      if (res.data.code == 0) {
        if (res.data.totalcount > 0) {
          that.data.pageIndex = that.data.pageIndex + 1;
          var recordList = res.data.data.recordList;
          if(recordList.length > 0){
            for (var index in recordList) {
              that.data.recordList.splice(that.data.recordList.length, 0, recordList[index]);
            }
            that.setData({
              hasData: true,
              recordList: that.data.recordList
            })
          }
        }
      }
      that.setData({ netWork: true, isLoading: false, })
      wx.hideNavigationBarLoading() //完成停止加载
      wx.stopPullDownRefresh() //停止下拉刷新
    },function () {
      that.setData({ netWork: false, hasData: false, isLoading: false, })
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.data.pageIndex = 1;
    this.setData({
      recordList:[],
      isLoading:true,
    });
    this.onHttpInit()
  },
  /**
   * 页面上拉触底事件的处理函数    加载更多
   */
  onReachBottom: function () {
    this.onHttpInit()
  },
})